package com.mediatecture.flex.component
{
	public class IFCXMLparcer
	{
		import mx.collections.ArrayCollection;
		
		protected var xmlTxt:String;
		protected var extPropIDArr:Array = new Array();
		protected var wallExtArr:Array = new Array();
		protected var dataArr:ArrayCollection = new ArrayCollection();
		
		protected var roofElev:Number = 0;
		protected var roofAngle:Number = 0;
		protected var roofArea:Number =0;
		
		public function IFCXMLparcer()
		{
			
		}
		public function Ifc2arr(rawData:String, dataXML:XML):XML
		{
			xmlTxt = '<uos>'+rawData.slice(rawData.indexOf('xsd">')+5,rawData.indexOf("</uos>"));
			getSlabs();
			getExtProp();
			getWindows();
			getDoors();
			
			return setXML(dataXML);
		}
		protected function getSlabs():void
		{
			var slabPattern:RegExp = /<IfcSlab id=(.*?)\<\/IfcSlab\>/gs;
			var slabArr:Array = new Array(xmlTxt.match(slabPattern));
			if(xmlTxt.indexOf('<IfcSlab id=') >0 )
			{
				var slabId:String = slabArr[0][0].slice(slabArr[0][0].indexOf('id="')+4 , slabArr[0][0].indexOf('">'));
				var slabpointsArr:Array = getSwept(slabId, "s");
				slabpointsArr.shift();
				roofArea = getArea(slabpointsArr);
			}
		}
		protected function getArea(points:Array):Number
		{
			var area:Number = 0;
			for(var i:uint=2 ; i<points.length-1 ; i++)
			{
				var angle:Number =  Math.atan2(points[i][1]-points[0][1],points[i][0]-points[0][0]) - Math.atan2(points[i-1][1]-points[0][1],points[i-1][0]-points[0][0]);
				var side0:Number = Math.sqrt(Math.pow(points[i-1][0]-points[0][0], 2)+Math.pow(points[i-1][1]-points[0][1], 2));
				var side1:Number = Math.sqrt(Math.pow(points[i][0]-points[0][0], 2)+Math.pow(points[i][1]-points[0][1], 2));
				area += side0*side1*Math.sin(angle)/2;
			}
			return area;
		}
		protected function getLevel(id:String):Number
		{
			var level:Number = 0;
			var stagePattern:RegExp = /<IfcRelContainedInSpatialStructure id=(.*?)\<\/IfcRelContainedInSpatialStructure\>/gs;
			var stageArr:Array = new Array(xmlTxt.match(stagePattern));
			var storeArr:Array = new Array();
			
			for(var i:uint=0 ; i<stageArr[0].length ; i++)
			{
				if(String(stageArr[0][i]).indexOf('ref="'+id+'"') > 0)
				{
					var storePattern:RegExp = /<IfcBuildingStorey(.*?)\/\>/gs;
					storeArr[i] = new Array(String(stageArr[0][i]).match(storePattern));
					for(var k:uint=0 ; k<storeArr[i][0].length ; k++)
					{
						var storeID:String = String(storeArr[i][0][k]).slice(String(storeArr[i][0][k]).indexOf('ref="')+5 , String(storeArr[i][0][k]).indexOf('"/>'));
						if(xmlTxt.indexOf('<IfcBuildingStorey id="'+storeID+'">') > 0)
						{
							var levelRef:String = xmlTxt.slice(xmlTxt.indexOf('<IfcBuildingStorey id="'+storeID+'">') , xmlTxt.indexOf('</IfcBuildingStorey>' , xmlTxt.indexOf('<IfcBuildingStorey id="'+storeID+'">'))+20);
							
							if(levelRef.indexOf('<Elevation>') > 0)
							{
								level = Number(levelRef.slice(levelRef.indexOf('<Elevation>')+11 , levelRef.indexOf('</Elevation>')));
							}
						}
					}
				}
			}
			return level;
		}
		protected function getExtProp():void
		{
			var psvPattern:RegExp = /<IfcPropertySingleValue id=(.*?)\<\/IfcPropertySingleValue\>/gs;
			var psvArr:Array = new Array(xmlTxt.match(psvPattern));
			for(var i:uint=0 ; i<psvArr[0].length ; i++)
			{
				if(String(psvArr[0][i]).indexOf("<Name>IsExternal</Name>") > 0 && String(psvArr[0][i]).indexOf("<IfcBoolean-wrapper>true</IfcBoolean-wrapper>") > 0)
				{
					var extPropID:String = String(psvArr[0][i]).slice(String(psvArr[0][i]).indexOf('id="')+4 , String(psvArr[0][i]).indexOf('">'));
					extPropIDArr.push(extPropID);
				}
			}
			getWallSet();
		}
		protected function getWallSet():void
		{
			var defPattern:RegExp = /<IfcRelDefinesByProperties id=(.*?)\<\/IfcRelDefinesByProperties\>/gs;
			var defArr:Array = new Array(xmlTxt.match(defPattern));
			var setArr:Array = new Array();
			var wallArr:Array = new Array();
			for(var i:uint=0 ; i<defArr[0].length ; i++)
			{
				var objPattern:RegExp = /<RelatedObjects(.*?)<IfcWallStandardCase(.*?)\/\>(.*?)\<\/RelatedObjects\>/gs;
				wallArr[i] = new Array(String(defArr[0][i]).match(objPattern));
				var setPattern:RegExp = /<RelatingPropertyDefinition(.*?)<IfcPropertySet(.*?)\/\>(.*?)\<\/RelatingPropertyDefinition\>/gs;
				setArr[i]  = new Array(String(defArr[0][i]).match(setPattern));
				
			}
			for(var j:uint=0 ; j<defArr[0].length ; j++)
			{
				for(var k:uint=0 ; k<wallArr[j][0].length ; k++)
				{
					var wallID:String = String(wallArr[j][0][k]).slice(String(wallArr[j][0][k]).indexOf('ref="')+5 , String(wallArr[j][0][k]).indexOf('"/>'));
					var setID:String = String(setArr[j][0][k]).slice(String(setArr[j][0][k]).indexOf('ref="')+5 , String(setArr[j][0][k]).indexOf('"/>'));
					var wallsett:Object = ({"w":wallID,"s":setID, "placeId":null, "placementId":null,  "levelInd":0 ,  "level":0, "location":null, "axis":null, "direction":null, "len":0, "height":null, 'dir':null, 'swept':null});
					if(getProp(setID))
					{
						wallExtArr.push(wallsett);
					}
				}
			}
			for(var l:uint=0 ; l<wallExtArr.length ; l++)
			{
				var placeId:String = getPlaceID(wallExtArr[l].w);
				wallExtArr[l].placementId = getPlacementID(placeId);
				var locObj:Object = getLocationObj(wallExtArr[l].placementId);
				wallExtArr[l].location = locObj.location;
				wallExtArr[l].axis = locObj.axis;
				wallExtArr[l].direction = locObj.direction;
				wallExtArr[l].level = getLevel(wallExtArr[l].w);
				wallExtArr[l].swept = getSwept(wallExtArr[l].w, "w");
				wallExtArr[l].height = wallExtArr[l].swept[0];
			}
			getWallsLen();
			getWalls();
		}
		protected function getProp(id:String):Boolean
		{
			var isExt:Boolean = false;
			if(xmlTxt.indexOf('<IfcPropertySet id="'+id+'">') > 0)
			{
				var propSet:String = xmlTxt.slice(xmlTxt.indexOf('<IfcPropertySet id="'+id+'">') , xmlTxt.indexOf('</IfcPropertySet>' , xmlTxt.indexOf('<IfcPropertySet id="'+id+'">'))+17);
				var svPattern:RegExp = /<IfcPropertySingleValue (.*?)\/\>/gs;
				var svArr:Array = new Array(propSet.match(svPattern));
				for(var i:uint=0 ; i<svArr[0].length ; i++)
				{
					if(String(svArr[0][i]).indexOf('ref="') > 0)
					{
						var propID:String = String(svArr[0][i]).slice(String(svArr[0][i]).indexOf('ref="')+5 , String(svArr[0][i]).indexOf('"/>'));
						for(var j:uint=0 ; j<extPropIDArr.length ; j++)
						{
							if(extPropIDArr[j] == propID)
							{
								isExt = true;
							}
						}
					}
				}
			}
			return isExt;
		}
		protected function getPlaceID(id:String):String
		{
			var ret:String = "";
			if(xmlTxt.indexOf('<IfcWallStandardCase id="'+id+'">') > 0)
			{
				var ref:String = xmlTxt.slice(xmlTxt.indexOf('<IfcWallStandardCase id="'+id+'">') , xmlTxt.indexOf('</IfcWallStandardCase>' , xmlTxt.indexOf('<IfcWallStandardCase id="'+id+'">'))+22);
				var pattern:RegExp = /<IfcLocalPlacement (.*?)\/\>/gs;
				var arr:Array = new Array(ref.match(pattern));
				for(var i:uint=0 ; i<arr[0].length ; i++)
				{
					if(String(arr[0][i]).indexOf('ref="') > 0)
					{
						ret = String(arr[0][i]).slice(String(arr[0][i]).indexOf('ref="')+5 , String(arr[0][i]).indexOf('"/>'));
					}
				}
			}
			return ret;
		}
		protected function getPlacementID(id:String):String
		{
			var ret:String = "";
			if(xmlTxt.indexOf('<IfcLocalPlacement id="'+id+'">') > 0)
			{
				var ref:String = xmlTxt.slice(xmlTxt.indexOf('<IfcLocalPlacement id="'+id+'">') , xmlTxt.indexOf('</IfcLocalPlacement>' , xmlTxt.indexOf('<IfcLocalPlacement id="'+id+'">'))+20);
				var pattern:RegExp = /<IfcAxis2Placement3D (.*?)\/\>/gs;
				var arr:Array = new Array(ref.match(pattern));
				for(var i:uint=0 ; i<arr[0].length ; i++)
				{
					if(String(arr[0][i]).indexOf('ref="') > 0)
					{
						ret = String(arr[0][i]).slice(String(arr[0][i]).indexOf('ref="')+5 , String(arr[0][i]).indexOf('"/>'));
					}
				}
			}
			return ret;
		}
		protected function getLocationObj(id:String):Object
		{
			var retId:Object =  ({"location":new Array, "axis":new Array, "direction":new Array});
			if(xmlTxt.indexOf('<IfcAxis2Placement3D id="'+id+'">') > 0)
			{
				var ref:String = xmlTxt.slice(xmlTxt.indexOf('<IfcAxis2Placement3D id="'+id+'">') , xmlTxt.indexOf('</IfcAxis2Placement3D>' , xmlTxt.indexOf('<IfcAxis2Placement3D id="'+id+'">'))+22);
				if(ref.indexOf('<Location>') > 0)
				{
					var refLoc:String = ref.slice(ref.indexOf('<Location>') , ref.indexOf('</Location>' , ref.indexOf('<Location>'))+11);
					if(refLoc.indexOf('<IfcCartesianPoint') > 0)
					{
						var refPoint:String = refLoc.slice(refLoc.indexOf('<IfcCartesianPoint') , refLoc.indexOf('"/>'));
						if(refPoint.indexOf('ref="') > 0)
						{
							var locationId:String = refPoint.slice(refPoint.indexOf('ref="')+5);
							if(xmlTxt.indexOf('<IfcCartesianPoint id="'+locationId+'">') > 0)
							{
								var refLocPoint:String = xmlTxt.slice(xmlTxt.indexOf('<IfcCartesianPoint id="'+locationId+'">') , xmlTxt.indexOf('</IfcCartesianPoint>' , xmlTxt.indexOf('<IfcCartesianPoint id="'+locationId+'">'))+20);
								if(refLocPoint.indexOf('<Coordinates') > 0)
								{
									var refLocPointCor:String = refLocPoint.slice(refLocPoint.indexOf('<Coordinates') , refLocPoint.indexOf('</Coordinates>' , refLocPoint.indexOf('<Coordinates'))+14);
									if(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="0">') > 0)
									{
										retId.location[0] =  refLocPointCor.slice(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="0">')+30 , refLocPointCor.indexOf('</IfcLengthMeasure>', refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="0">')) );
									}
									if(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="1">') > 0)
									{
										retId.location[1] =  refLocPointCor.slice(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="1">')+30 , refLocPointCor.indexOf('</IfcLengthMeasure>', refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="1">')) );
									}
									if(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="2">') > 0)
									{
										retId.location[2] =  refLocPointCor.slice(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="2">')+30 , refLocPointCor.indexOf('</IfcLengthMeasure>', refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="2">')) );
									}
								}
							}
						}
					}
				}
				if(ref.indexOf('<Axis>') > 0)
				{
					var refAxis:String = ref.slice(ref.indexOf('<Axis>') , ref.indexOf('</Axis>' , ref.indexOf('<Axis>'))+7);
					if(refAxis.indexOf('<IfcDirection') > 0)
					{
						var refAxDir:String = refAxis.slice(refAxis.indexOf('<IfcDirection') , refAxis.indexOf('"/>'));
						if(refAxDir.indexOf('ref="') > 0)
						{
							var axisId:String = refAxDir.slice(refAxDir.indexOf('ref="')+5);
							if(xmlTxt.indexOf('<IfcDirection id="'+axisId+'">') > 0)
							{
								var refAxisDir:String = xmlTxt.slice(xmlTxt.indexOf('<IfcDirection id="'+axisId+'">') , xmlTxt.indexOf('</IfcDirection>' , xmlTxt.indexOf('<IfcDirection id="'+axisId+'">'))+15);
								if(refAxisDir.indexOf('<DirectionRatios') > 0)
								{
									var refAxDirectionRatios:String = refAxisDir.slice(refAxisDir.indexOf('<DirectionRatios') , refAxisDir.indexOf('</DirectionRatios>' , refAxisDir.indexOf('<DirectionRatios'))+18);
									if(refAxDirectionRatios.indexOf('<exp:double-wrapper pos="0">') > 0)
									{
										retId.axis[0] =  refAxDirectionRatios.slice(refAxDirectionRatios.indexOf('<exp:double-wrapper pos="0">')+28 , refAxDirectionRatios.indexOf('</exp:double-wrapper>', refAxDirectionRatios.indexOf('<exp:double-wrapper pos="0">')) );
									}
									if(refAxDirectionRatios.indexOf('<exp:double-wrapper pos="1">') > 0)
									{
										retId.axis[1] =  refAxDirectionRatios.slice(refAxDirectionRatios.indexOf('<exp:double-wrapper pos="1">')+28 , refAxDirectionRatios.indexOf('</exp:double-wrapper>', refAxDirectionRatios.indexOf('<exp:double-wrapper pos="1">')) );
									}
									if(refAxDirectionRatios.indexOf('<exp:double-wrapper pos="2">') > 0)
									{
										retId.axis[2] =  refAxDirectionRatios.slice(refAxDirectionRatios.indexOf('<exp:double-wrapper pos="2">')+28 , refAxDirectionRatios.indexOf('</exp:double-wrapper>', refAxDirectionRatios.indexOf('<exp:double-wrapper pos="2">')) );
									}
								}
							}
						}
					}
				}
				if(ref.indexOf('<RefDirection>') > 0)
				{
					var refDir:String = ref.slice(ref.indexOf('<RefDirection>') , ref.indexOf('</RefDirection>' , ref.indexOf('<RefDirection>'))+15);
					if(refDir.indexOf('<IfcDirection') > 0)
					{
						var refDirec:String = refDir.slice(refDir.indexOf('<IfcDirection') , refDir.indexOf('"/>'));
						if(refDirec.indexOf('ref="') > 0)
						{
							var dirId:String = refDirec.slice(refDirec.indexOf('ref="')+5);
							if(xmlTxt.indexOf('<IfcDirection id="'+dirId+'">') > 0)
							{
								var refDirection:String = xmlTxt.slice(xmlTxt.indexOf('<IfcDirection id="'+dirId+'">') , xmlTxt.indexOf('</IfcDirection>' , xmlTxt.indexOf('<IfcDirection id="'+dirId+'">'))+15);
								if(refDirection.indexOf('<DirectionRatios') > 0)
								{
									var refDirectionRatios:String = refDirection.slice(refDirection.indexOf('<DirectionRatios') , refDirection.indexOf('</DirectionRatios>' , refDirection.indexOf('<DirectionRatios'))+18);
									if(refDirectionRatios.indexOf('<exp:double-wrapper pos="0">') > 0)
									{
										retId.direction[0] =  refDirectionRatios.slice(refDirectionRatios.indexOf('<exp:double-wrapper pos="0">')+28 , refDirectionRatios.indexOf('</exp:double-wrapper>', refDirectionRatios.indexOf('<exp:double-wrapper pos="0">')) );
									}
									if(refDirectionRatios.indexOf('<exp:double-wrapper pos="1">') > 0)
									{
										retId.direction[1] =  refDirectionRatios.slice(refDirectionRatios.indexOf('<exp:double-wrapper pos="1">')+28 , refDirectionRatios.indexOf('</exp:double-wrapper>', refDirectionRatios.indexOf('<exp:double-wrapper pos="1">')) );
									}
									if(refDirectionRatios.indexOf('<exp:double-wrapper pos="2">') > 0)
									{
										retId.direction[2] =  refDirectionRatios.slice(refDirectionRatios.indexOf('<exp:double-wrapper pos="2">')+28 , refDirectionRatios.indexOf('</exp:double-wrapper>', refDirectionRatios.indexOf('<exp:double-wrapper pos="2">')) );
									}
								}
							}
						}
					}
				}
			}
			return retId;
		}
		protected function getWallsLen():void
		{
			var levInd:uint = 0;
			var levHminArr:Array = [99999999];
			var levHmaxArr:Array = [0];
			var lastLevel:Number;
			for(var i:uint=0 ; i<=wallExtArr.length-1 ; i++)
			{
				levHminArr[levInd] = Math.min(levHminArr[levInd] , wallExtArr[i].height);
				levHmaxArr[levInd] = Math.max(levHmaxArr[levInd] , wallExtArr[i].height);
				wallExtArr[i].levelInd = levInd;
				if(i < wallExtArr.length-1)
				{
					if(wallExtArr[i].level < wallExtArr[i+1].level)
					{
						levInd++;
						levHminArr.push(99999999);
						levHmaxArr.push(0);
						lastLevel = wallExtArr[i+1].level;
					}
				}
				for(var j:uint=0 ; j<2 ; j++)
				{
					wallExtArr[i].len += Math.max(Math.abs(Number(wallExtArr[i].swept[2][j])-Number(wallExtArr[i].swept[1][j])) , Math.abs(Number(wallExtArr[i].swept[4][j])-Number(wallExtArr[i].swept[3][j])));
				}
			}
			for(var l:uint=0 ; l<=wallExtArr.length-1 ; l++)
			{
				if(wallExtArr[l].height > levHminArr[wallExtArr[l].levelInd])
				{
					wallExtArr[l].height = (wallExtArr[l].height + levHminArr[wallExtArr[l].levelInd])/2;
				}
			}
			roofElev = getBuildingHeight()-lastLevel-levHminArr[levHminArr.length-1];
		}
		protected function getBuildingHeight():Number
		{
			var bh:Number = 0;
			var hiPattern:RegExp = /<IfcLengthMeasure exp:pos="2">(.*?)\<\/IfcLengthMeasure\>/gs;
			var hiArr:Array = new Array(xmlTxt.match(hiPattern));
			for(var i:uint=0 ; i<hiArr[0].length ; i++)
			{
				var bhStr:String = hiArr[0][i].slice(hiArr[0][i].indexOf('<IfcLengthMeasure exp:pos="2">')+30 , hiArr[0][i].indexOf('</IfcLengthMeasure>'));
				bh = Math.max(bh , Number(bhStr));
			}
			return bh;
		}
		protected function getSwept(id:String, type:String):Array
		{
			var patern0:String;
			var patern1:String;
			if(type == "s")
			{
				patern0 = '<IfcSlab id="'+id+'">';
				patern1 = '</IfcSlab>';
			}
			else
			{
				patern0 = '<IfcWallStandardCase id="'+id+'">';
				patern1 = '</IfcWallStandardCase>';
			}
			var ret:Array = [0];
			if(xmlTxt.indexOf(patern0) > 0)
			{
				var ref:String = xmlTxt.slice(xmlTxt.indexOf(patern0) , xmlTxt.indexOf(patern1 , xmlTxt.indexOf(patern0))+22);
				if(ref.indexOf('<Representation>') > 0)
				{
					var refRepr:String = ref.slice(ref.indexOf('<Representation>') , ref.indexOf('</Representation>' , ref.indexOf('<Representation>'))+18);
					if(refRepr.indexOf('<IfcProductDefinitionShape') > 0)
					{
						var refProdDefShape:String = refRepr.slice(refRepr.indexOf('<IfcProductDefinitionShape') , refRepr.indexOf('"/>'));
						if(refProdDefShape.indexOf('ref="') > 0)
						{
							var prodDefShapeId:String = refProdDefShape.slice(refProdDefShape.indexOf('ref="')+5);
							if(xmlTxt.indexOf('<IfcProductDefinitionShape id="'+prodDefShapeId+'">') > 0)
							{
								var prodDefShape:String = xmlTxt.slice(xmlTxt.indexOf('<IfcProductDefinitionShape id="'+prodDefShapeId+'">') , xmlTxt.indexOf('</IfcProductDefinitionShape>' , xmlTxt.indexOf('<IfcProductDefinitionShape id="'+prodDefShapeId+'">'))+28);
								if(prodDefShape.indexOf('<IfcShapeRepresentation exp:pos="0"') > 0)
								{
									var shapeRep:String = prodDefShape.slice(prodDefShape.indexOf('<IfcShapeRepresentation exp:pos="0"') , prodDefShape.indexOf('"/>'));
									if(shapeRep.indexOf('ref="') > 0)
									{
										var shapeRepId:String = shapeRep.slice(shapeRep.indexOf('ref="')+5);
										if(xmlTxt.indexOf('<IfcShapeRepresentation id="'+shapeRepId+'">') > 0)
										{
											var refShapeRep:String = xmlTxt.slice(xmlTxt.indexOf('<IfcShapeRepresentation id="'+shapeRepId+'">') , xmlTxt.indexOf('</IfcShapeRepresentation>' , xmlTxt.indexOf('<IfcShapeRepresentation id="'+shapeRepId+'">'))+25);
											if(refShapeRep.indexOf('<Items') > 0)
											{
												var items:String = refShapeRep.slice(refShapeRep.indexOf('<Items') , refShapeRep.indexOf('</Items>' , refShapeRep.indexOf('<Items'))+8);
												if(items.indexOf('<IfcExtrudedAreaSolid') > 0)
												{
													var extrArSol:String = items.slice(items.indexOf('<IfcExtrudedAreaSolid') , items.indexOf('"/>'));
													if(extrArSol.indexOf('ref="') > 0)
													{
														var extrArSolId:String = extrArSol.slice(extrArSol.indexOf('ref="')+5);
														if(xmlTxt.indexOf('<IfcExtrudedAreaSolid id="'+extrArSolId+'">') > 0)
														{
															var refExtrArSol:String = xmlTxt.slice(xmlTxt.indexOf('<IfcExtrudedAreaSolid id="'+extrArSolId+'">') , xmlTxt.indexOf('</IfcExtrudedAreaSolid>' , xmlTxt.indexOf('<IfcExtrudedAreaSolid id="'+extrArSolId+'">'))+23);
															if(refExtrArSol.indexOf('<Depth>') > 0)
															{
																ret[0] = Number(refExtrArSol.slice(refExtrArSol.indexOf('<Depth>')+7 , refExtrArSol.indexOf('</Depth>')));
															}
															if(refExtrArSol.indexOf('<SweptArea>') > 0)
															{
																var strSweptArea:String = refExtrArSol.slice(refExtrArSol.indexOf('<SweptArea>')+11 , refExtrArSol.indexOf('</SweptArea>'));
																if(strSweptArea.indexOf('<IfcArbitraryClosedProfileDef') > 0)
																{
																	var closedProfileDef:String = strSweptArea.slice(strSweptArea.indexOf('<IfcArbitraryClosedProfileDef') , strSweptArea.indexOf('"/>'));
																	if(closedProfileDef.indexOf('ref="') > 0)
																	{
																		var closedProfileDefId:String = closedProfileDef.slice(closedProfileDef.indexOf('ref="')+5);
																		if(xmlTxt.indexOf('<IfcArbitraryClosedProfileDef id="'+closedProfileDefId+'">') > 0)
																		{
																			var arbitraryClosedProfileDef:String = xmlTxt.slice(xmlTxt.indexOf('<IfcArbitraryClosedProfileDef id="'+closedProfileDefId+'">') , xmlTxt.indexOf('</IfcArbitraryClosedProfileDef>' , xmlTxt.indexOf('<IfcArbitraryClosedProfileDef id="'+closedProfileDefId+'">'))+31);
																			if(arbitraryClosedProfileDef.indexOf('<OuterCurve>') > 0)
																			{
																				var outerCurve:String = arbitraryClosedProfileDef.slice(arbitraryClosedProfileDef.indexOf('<OuterCurve>')+12 , arbitraryClosedProfileDef.indexOf('</OuterCurve>'));
																				if(outerCurve.indexOf('<IfcPolyline') > 0)
																				{
																					var polylineRef:String = outerCurve.slice(outerCurve.indexOf('<IfcPolyline') , outerCurve.indexOf('"/>'));
																					if(polylineRef.indexOf('ref="') > 0)
																					{
																						var polylineId:String = polylineRef.slice(polylineRef.indexOf('ref="')+5);
																						if(xmlTxt.indexOf('<IfcPolyline id="'+polylineId+'">') > 0)
																						{
																							var polyline:String = xmlTxt.slice(xmlTxt.indexOf('<IfcPolyline id="'+polylineId+'">') , xmlTxt.indexOf('</IfcPolyline>' , xmlTxt.indexOf('<IfcPolyline id="'+polylineId+'">'))+14);
																							if(polyline.indexOf('<Points') > 0)
																							{
																								var points:String = polyline.slice(polyline.indexOf('<Points')+12 , polyline.indexOf('</Points>'));
																								var pointsPattern:RegExp = /<IfcCartesianPoint exp:pos="(.*?)\/\>/gs;
																								var pointsArr:Array = new Array(points.match(pointsPattern));
																								for(var i:uint=0 ; i<pointsArr[0].length ; i++)
																								{
																									if(pointsArr[0][i].indexOf('ref="') > 0)
																									{
																										var pointId:String = pointsArr[0][i].slice(pointsArr[0][i].indexOf('ref="')+5, pointsArr[0][i].indexOf('"/>'));
																										ret.push(getWallPoints(pointId));
																									}
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			return ret;
		}
		protected function getWallPoints(id:String):Array
		{
			var ret:Array = [0,0];
			if(xmlTxt.indexOf('<IfcCartesianPoint id="'+id+'">') > 0)
			{
				var refLocPoint:String = xmlTxt.slice(xmlTxt.indexOf('<IfcCartesianPoint id="'+id+'">') , xmlTxt.indexOf('</IfcCartesianPoint>' , xmlTxt.indexOf('<IfcCartesianPoint id="'+id+'">'))+20);
				if(refLocPoint.indexOf('<Coordinates') > 0)
				{
					var refLocPointCor:String = refLocPoint.slice(refLocPoint.indexOf('<Coordinates') , refLocPoint.indexOf('</Coordinates>' , refLocPoint.indexOf('<Coordinates'))+14);
					if(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="0">') > 0)
					{
						ret[0] =  refLocPointCor.slice(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="0">')+30 , refLocPointCor.indexOf('</IfcLengthMeasure>', refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="0">')) );
					}
					if(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="1">') > 0)
					{
						ret[1] =  refLocPointCor.slice(refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="1">')+30 , refLocPointCor.indexOf('</IfcLengthMeasure>', refLocPointCor.indexOf('<IfcLengthMeasure exp:pos="1">')) );
					}
				}
			}
			return ret;
		}
		protected function getWalls():void
		{
			for(var i:uint=0 ; i<wallExtArr.length ; i++)
			{
				var wallArea:Number = wallExtArr[i].len*wallExtArr[i].height/1000000;
				var dir:String = "";
				if(Number(wallExtArr[i].direction[0]) > 0.05)
				{
					dir += "s";
				}
				else if(Number(wallExtArr[i].direction[0]) < -0.05)
				{
					dir += "n";
				}
				if(Number(wallExtArr[i].direction[1]) > 0.05)
				{
					dir += "e";
				}
				else if(Number(wallExtArr[i].direction[1]) < -0.05)
				{
					dir += "w";
				}	
				wallExtArr[i].dir = dir;
				dataArr.addItem({'id':wallExtArr[i].w , 'name':'wall' , 'area':wallArea, 'dir':dir, 'trans':false, 'level':wallExtArr[i].levelInd, 'direction':wallExtArr[i].direction});
			}
			roofAngle = Math.atan(roofElev/Math.sqrt(roofArea));
			roofArea = roofArea/Math.cos(roofAngle)/1000000;
			dataArr.addItem({'name':'roof' , 'area':roofArea, 'trans':false});
		}
		protected function getWindows():void
		{
			var winPattern:RegExp = /<IfcWindow id=(.*?)\<\/IfcWindow\>/gs;
			var winArr:Array = new Array(xmlTxt.match(winPattern));
			for(var i:uint=0 ; i<winArr[0].length ; i++)
			{
				var winId:String = winArr[0][i].slice(winArr[0][i].indexOf('id="')+4 , winArr[0][i].indexOf('">'));
				var winArea:Number = Number(winArr[0][i].slice(winArr[0][i].indexOf('OverallHeight>')+14,winArr[0][i].indexOf("</OverallHeight")))*Number(winArr[0][i].slice(winArr[0][i].indexOf('OverallWidth>')+13,winArr[0][i].indexOf("</OverallWidth")))/1000000;
				var parentId:String = getParent(winId, 'IfcWindow');
				for(var j:uint=0 ; j<wallExtArr.length ; j++)
				{
					if(wallExtArr[j].w == parentId)
					{
						dataArr.addItem({'id':winId , 'name':'window' , 'area':winArea, 'parent':parentId, 'dir':wallExtArr[j].dir, 'trans':true, 'level':wallExtArr[j].levelInd, 'direction':wallExtArr[j].direction});
						break;
					}
				}
			}
		}
		protected function getDoors():void
		{
			var doorPattern:RegExp = /<IfcDoor id=(.*?)\<\/IfcDoor\>/gs;
			var doorArr:Array = new Array(xmlTxt.match(doorPattern));
			for(var i:uint=0 ; i<doorArr[0].length ; i++)
			{
				var doorId:String = doorArr[0][i].slice(doorArr[0][i].indexOf('id="')+4 , doorArr[0][i].indexOf('">'));
				var doorArea:Number = Number(doorArr[0][i].slice(doorArr[0][i].indexOf('OverallHeight>')+14,doorArr[0][i].indexOf("</OverallHeight")))*Number(doorArr[0][i].slice(doorArr[0][i].indexOf('OverallWidth>')+13,doorArr[0][i].indexOf("</OverallWidth")))/1000000;
				var parentId:String = getParent(doorId, 'IfcDoor');
				for(var j:uint=0 ; j<wallExtArr.length ; j++)
				{
					if(wallExtArr[j].w == parentId)
					{
						dataArr.addItem({'id':doorId , 'name':'door' , 'area':doorArea, 'parent':parentId, 'dir':wallExtArr[j].dir, 'trans':false, 'level':wallExtArr[j].levelInd, 'direction':wallExtArr[j].direction});
						break;
					}
				}
			}
		}
		protected function getParent(id:String, type:String):String
		{
			var ret:String = "";
			var fillsPattern:RegExp = /<IfcRelFillsElement id=(.*?)\<\/IfcRelFillsElement\>/gs;
			var fillsArr:Array = new Array(xmlTxt.match(fillsPattern));
			for(var i:uint=0 ; i<fillsArr[0].length ; i++)
			{
				if(fillsArr[0][i].indexOf('<RelatedBuildingElement>') > 0)
				{
					var building:String = fillsArr[0][i].slice(fillsArr[0][i].indexOf('<RelatedBuildingElement>') , fillsArr[0][i].indexOf('</RelatedBuildingElement>' , fillsArr[0][i].indexOf('<RelatedBuildingElement>'))+25);
					if(building.indexOf('<'+type) > 0)
					{
						var buildType:String = building.slice(building.indexOf('<'+type) , building.indexOf('"/>'));
						if(buildType.indexOf('ref="') > 0)
						{
							var buildTypeId:String = buildType.slice(buildType.indexOf('ref="')+5);
							if(buildTypeId == id)
							{
								if(fillsArr[0][i].indexOf('<RelatingOpeningElement>') > 0)
								{
									var opening:String = fillsArr[0][i].slice(fillsArr[0][i].indexOf('<RelatingOpeningElement>') , fillsArr[0][i].indexOf('</RelatingOpeningElement>' , fillsArr[0][i].indexOf('<RelatingOpeningElement>'))+25);
									if(opening.indexOf('<IfcOpeningElement') > 0)
									{
										var openingEl:String = opening.slice(opening.indexOf('<IfcOpeningElement') , opening.indexOf('"/>'));
										if(openingEl.indexOf('ref="') > 0)
										{
											var openingId:String = openingEl.slice(openingEl.indexOf('ref="')+5);
											var voidsPattern:RegExp = /<IfcRelVoidsElement id=(.*?)\<\/IfcRelVoidsElement\>/gs;
											var voidsArr:Array = new Array(xmlTxt.match(voidsPattern));
											for(var j:uint=0 ; j<voidsArr[0].length ; j++)
											{
												if(voidsArr[0][j].indexOf('<RelatedOpeningElement>') > 0)
												{
													var openings:String = voidsArr[0][j].slice(voidsArr[0][j].indexOf('<RelatedOpeningElement>') , voidsArr[0][j].indexOf('</RelatedOpeningElement>' , voidsArr[0][j].indexOf('<RelatedOpeningElement>'))+24);
													if(openings.indexOf('<IfcOpeningElement') > 0)
													{
														var openingsRef:String = openings.slice(openings.indexOf('<IfcOpeningElement') , openings.indexOf('"/>'));
														if(openingsRef.indexOf('ref="') > 0)
														{
															var openRef:String = openingsRef.slice(openingsRef.indexOf('ref="')+5);
															if(openRef == openingId)
															{
																if(voidsArr[0][j].indexOf('<RelatingBuildingElement>') > 0)
																{
																	var buildings:String = voidsArr[0][j].slice(voidsArr[0][j].indexOf('<RelatingBuildingElement>') , voidsArr[0][j].indexOf('</RelatingBuildingElement>' , voidsArr[0][j].indexOf('<RelatingBuildingElement>'))+26);
																	if(buildings.indexOf('<IfcWallStandardCase') > 0)
																	{
																		var wallRef:String = buildings.slice(buildings.indexOf('<IfcWallStandardCase') , buildings.indexOf('"/>'));
																		if(wallRef.indexOf('ref="') > 0)
																		{
																			var wallId:String = wallRef.slice(wallRef.indexOf('ref="')+5);
																			ret = wallId;
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}					
			}
			return ret;
		}
		protected function setXML(dataXML:XML):XML
		{
			var wallsArea:Array = new Array;
			var doorsArea:Array = new Array;
			var roofArea:Array = new Array;
			var winArea:Array = new Array;
			var levelsNum:uint = 1;
			
			for(var j:uint=0 ; j<dataArr.length ; j++)
			{
				if(dataArr[j].level != undefined)
				{
					levelsNum = Math.max(levelsNum, dataArr[j].level+1);
				}
			}
			for(var l:uint=0 ; l<levelsNum ; l++)
			{
				wallsArea[l] = [0,0,0,0,0];
				doorsArea[l] = [0,0,0,0,0];
				roofArea[l] = 0;
				winArea[l] = [0,0,0,0,0];
				if(dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[l] == null)
				{
					dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[l] = dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[0].copy();
				}
			}
			for(var i:uint=0 ; i<dataArr.length ; i++)
			{
				if(dataArr[i].name == "roof")
				{
					roofArea[levelsNum-1] += dataArr[i].area;
				}
				else
				{
					switch (dataArr[i].dir)
					{
						case "n":
							switch (dataArr[i].name)
							{
								case "wall":
									wallsArea[dataArr[i].level][1] += dataArr[i].area;
									wallsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "door":
									doorsArea[dataArr[i].level][1] += dataArr[i].area;
									doorsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "window":
									winArea[dataArr[i].level][1] += dataArr[i].area;
									winArea[dataArr[i].level][0] += dataArr[i].area;
									break;
							}
							break;
						case "ne":
							switch (dataArr[i].name)
							{
								case "wall":
									wallsArea[dataArr[i].level][1] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									wallsArea[dataArr[i].level][2] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									wallsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "door":
									doorsArea[dataArr[i].level][1] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									doorsArea[dataArr[i].level][2] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									doorsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "window":
									winArea[dataArr[i].level][1] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									winArea[dataArr[i].level][2] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									winArea[dataArr[i].level][0] += dataArr[i].area;
									break;
							}
							break;
						case "e":
							switch (dataArr[i].name)
							{
								case "wall":
									wallsArea[dataArr[i].level][2] += dataArr[i].area;
									wallsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "door":
									doorsArea[dataArr[i].level][2] += dataArr[i].area;
									doorsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "window":
									winArea[dataArr[i].level][2] += dataArr[i].area;
									winArea[dataArr[i].level][0] += dataArr[i].area;
									break;
							}
							break;
						case "se":
							switch (dataArr[i].name)
							{
								case "wall":
									wallsArea[dataArr[i].level][2] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									wallsArea[dataArr[i].level][3] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									wallsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "door":
									doorsArea[dataArr[i].level][2] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									doorsArea[dataArr[i].level][3] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									doorsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "window":
									winArea[dataArr[i].level][2] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									winArea[dataArr[i].level][3] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									winArea[dataArr[i].level][0] += dataArr[i].area;
									break;
							}
							break;
						case "s":
							switch (dataArr[i].name)
							{
								case "wall":
									wallsArea[dataArr[i].level][3] += dataArr[i].area;
									wallsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "door":
									doorsArea[dataArr[i].level][3] += dataArr[i].area;
									doorsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "window":
									winArea[dataArr[i].level][3] += dataArr[i].area;
									winArea[dataArr[i].level][0] += dataArr[i].area;
									break;
							}
							break;
						case "sw":
							switch (dataArr[i].name)
							{
								case "wall":
									wallsArea[dataArr[i].level][3] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									wallsArea[dataArr[i].level][4] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									wallsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "door":
									doorsArea[dataArr[i].level][3] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									doorsArea[dataArr[i].level][4] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									doorsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "window":
									winArea[dataArr[i].level][3] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									winArea[dataArr[i].level][4] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									winArea[dataArr[i].level][0] += dataArr[i].area;
									break;
							}
							break;
						case "w":
							switch (dataArr[i].name)
							{
								case "wall":
									wallsArea[dataArr[i].level][4] += dataArr[i].area;
									wallsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "door":
									doorsArea[dataArr[i].level][4] += dataArr[i].area;
									doorsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "window":
									winArea[dataArr[i].level][4] += dataArr[i].area;
									winArea[dataArr[i].level][0] += dataArr[i].area;
									break;
							}
							break;
						case "nw":
							switch (dataArr[i].name)
							{
								case "wall":
									wallsArea[dataArr[i].level][4] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									wallsArea[dataArr[i].level][1] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									wallsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "door":
									doorsArea[dataArr[i].level][4] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									doorsArea[dataArr[i].level][1] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									doorsArea[dataArr[i].level][0] += dataArr[i].area;
									break;
								case "window":
									winArea[dataArr[i].level][4] += dataArr[i].area*Math.pow(dataArr[i].direction[1],2);
									winArea[dataArr[i].level][1] += dataArr[i].area*Math.pow(dataArr[i].direction[0],2);
									winArea[dataArr[i].level][0] += dataArr[i].area;
									break;
							}
							break;
					}
				}
			}
			
			var kInd:uint = 1;
			for(var k:uint=1 ; k<=levelsNum ; k++)
			{
				if(wallsArea[k-1][0] > 0)
				{
					dataXML.GeometryOverviewTab.OpaqueComponentsArea["Purpose_"+kInd] = "Walls stage "+k;
					dataXML.GeometryOverviewTab.OpaqueComponentsArea["NetArea_"+kInd] =  Math.round(wallsArea[k-1][0]*1000)/1000-Math.round(doorsArea[k-1][0]*1000)/1000-Math.round(winArea[k-1][0]*1000)/1000;
					if(dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd] == null)
					{
						dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd] = dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].copy();
					}
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].ComponentName = "Walls stage "+k;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].ComponentFloor = String(k);
					//dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_Area = Math.round(wallsArea[k-1]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_North = Math.round(wallsArea[k-1][1]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_East = Math.round(wallsArea[k-1][2]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_South = Math.round(wallsArea[k-1][3]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_West = Math.round(wallsArea[k-1][4]*1000)/1000;
					//dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_Glazing_Area = Math.round(winArea[k-1]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_Glazing_North = Math.round(winArea[k-1][1]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_Glazing_East = Math.round(winArea[k-1][2]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_Glazing_South = Math.round(winArea[k-1][3]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_Glazing_West = Math.round(winArea[k-1][4]*1000)/1000;
					kInd++;
				}
				if(doorsArea[k-1][0] > 0)
				{
					dataXML.GeometryOverviewTab.OpaqueComponentsArea["Purpose_"+kInd] = "Doors stage "+k;
					dataXML.GeometryOverviewTab.OpaqueComponentsArea["NetArea_"+kInd] = Math.round(doorsArea[k-1][0]*1000)/1000;
					if(dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd] == null)
					{
						dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd] = dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].copy();
					}
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].ComponentName = "Doors stage "+k;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].ComponentFloor = String(k);
					//dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_Area = Math.round(doorsArea[k-1]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_North = Math.round(doorsArea[k-1][1]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_East = Math.round(doorsArea[k-1][2]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_South = Math.round(doorsArea[k-1][3]*1000)/1000;
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_West = Math.round(doorsArea[k-1][4]*1000)/1000;
					kInd++;
				}
				if(winArea[k-1][0] > 0)
				{
					dataXML.GeometryOverviewTab.TransparentComponentsArea["Purpose_"+k] = "Windows stage "+k;
					dataXML.GeometryOverviewTab.TransparentComponentsArea["NetArea_"+k] = Math.round(winArea[k-1][0]*1000)/1000;
					dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[k-1].ComponentName = "Windows stage "+k;
					dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[k-1].ComponentFloor = String(k);
					//dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[k-1].C_Area = Math.round(winArea[k-1]*1000)/1000;
					dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[k-1].C_North = Math.round(winArea[k-1][1]*1000)/1000;
					dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[k-1].C_East = Math.round(winArea[k-1][2]*1000)/1000;
					dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[k-1].C_South = Math.round(winArea[k-1][3]*1000)/1000;
					dataXML.GeometryDetailviewTab.TransparentComponentsArea.Component[k-1].C_West = Math.round(winArea[k-1][4]*1000)/1000;
				}
			}
			if(roofArea[levelsNum-1] > 0)
			{
				dataXML.GeometryOverviewTab.OpaqueComponentsArea["Purpose_"+kInd] = "Roof";
				dataXML.GeometryOverviewTab.OpaqueComponentsArea["NetArea_"+kInd] = Math.round(roofArea[levelsNum-1]*1000)/1000;
				if(dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd] == null)
				{
					dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd] = dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].copy();
				}
				dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].ComponentName = "Roof";
				dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].ComponentFloor = String(k);
				dataXML.GeometryDetailviewTab.OpaqueComponentsArea.Component[kInd-1].C_Area = Math.round(roofArea[levelsNum-1]*1000)/1000;
			}
			
			return dataXML;
		}
	}
}